package cn.siat.gene.controller;

import cn.siat.common.core.domain.R;
import cn.siat.common.core.web.domain.AjaxResult;
import cn.siat.gene.domain.MinioFile;
import cn.siat.gene.service.MinioFileService;
import cn.siat.system.api.domain.SysFile;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/minio")
@RequiredArgsConstructor
@Slf4j
public class MinioController {
    private final MinioFileService minioFileService;
    @PostMapping("upload")
    public AjaxResult upload(MultipartFile file,String md5) throws Exception
    {
            return AjaxResult.success(minioFileService.uploadFile(file,md5));
    }
    @ApiOperation("创建分片上传")
    @PostMapping("/multipart/create")
    public AjaxResult createMultipartUpload(@RequestBody List<MinioFile> list
    ) {
        return minioFileService.createMultipartUpload(list);
    }
    @ApiOperation("切片上传完成")
    @GetMapping("/slice/complete")
    public AjaxResult sliceComplete(Integer id,Integer completeChunkNumber
    ) {
        return minioFileService.sliceComplete(id,completeChunkNumber);
    }
    @ApiOperation("合并分片")
    @PostMapping("/multipart/complete")
    public AjaxResult completeMultipartUpload(
            @RequestBody
            List<MinioFile> list
    ) {
        return minioFileService.completeMultipartUpload(list);
    }
    @ApiOperation("获取下载连接")
    @GetMapping("/getDownLoadUrl")
    public AjaxResult getDownLoadUrl(String md5){
        return AjaxResult.success("操作成功",minioFileService.getDownLoadUrl(md5));
    }
    @ApiOperation("文件删除")
    @DeleteMapping("/{fileName}")
    public void remove(
            @PathVariable("fileName")
            String fileName
    ) {
        minioFileService.remove(fileName);
    }
}
